package org.example.system.validator;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.util.Arrays;
import java.util.List;

public class StatusValidator implements ConstraintValidator<Status,Integer> {

    private List<String> values;
    @Override
    public void initialize(Status constraintAnnotation) {
        values = Arrays.asList(constraintAnnotation.statusValues());
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
        if(value != null) {
            if(! values.contains(value.toString())){
                return false;
            }
        }
        return true;
    }
}
